/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     CWI Amsterdam - initial API and implementation
 *
 * $Id$
 */
package nl.cwi.arne.impl;

import java.util.Collection;

import nl.cwi.arne.Edge;
import nl.cwi.arne.Network;
import nl.cwi.arne.NetworkActivation;
import nl.cwi.arne.Node;
import nl.cwi.arne.factory.ArnePackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Network</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#getNodes <em>Nodes</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#getEdges <em>Edges</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#getActivations <em>Activations</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#isCheckEquivalence <em>Check Equivalence</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#isCheckModalFormula <em>Check Modal Formula</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#isCheckStableRegions <em>Check Stable Regions</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#getModalFormula <em>Modal Formula</em>}</li>
 *   <li>{@link nl.cwi.arne.impl.NetworkImpl#getStableRegions <em>Stable Regions</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NetworkImpl extends MinimalEObjectImpl implements Network {
	/**
	 * The cached value of the '{@link #getNodes() <em>Nodes</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNodes()
	 * @generated
	 * @ordered
	 */
	protected EList<Node> nodes;

	/**
	 * The cached value of the '{@link #getEdges() <em>Edges</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEdges()
	 * @generated
	 * @ordered
	 */
	protected EList<Edge> edges;

	/**
	 * The cached value of the '{@link #getActivations() <em>Activations</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getActivations()
	 * @generated
	 * @ordered
	 */
	protected EList<NetworkActivation> activations;

	/**
	 * The default value of the '{@link #isCheckEquivalence() <em>Check Equivalence</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckEquivalence()
	 * @generated
	 * @ordered
	 */
	protected static final boolean CHECK_EQUIVALENCE_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isCheckEquivalence() <em>Check Equivalence</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckEquivalence()
	 * @generated
	 * @ordered
	 */
	protected boolean checkEquivalence = CHECK_EQUIVALENCE_EDEFAULT;

	/**
	 * The default value of the '{@link #isCheckModalFormula() <em>Check Modal Formula</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckModalFormula()
	 * @generated
	 * @ordered
	 */
	protected static final boolean CHECK_MODAL_FORMULA_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isCheckModalFormula() <em>Check Modal Formula</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckModalFormula()
	 * @generated
	 * @ordered
	 */
	protected boolean checkModalFormula = CHECK_MODAL_FORMULA_EDEFAULT;

	/**
	 * The default value of the '{@link #isCheckStableRegions() <em>Check Stable Regions</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckStableRegions()
	 * @generated
	 * @ordered
	 */
	protected static final boolean CHECK_STABLE_REGIONS_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isCheckStableRegions() <em>Check Stable Regions</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isCheckStableRegions()
	 * @generated
	 * @ordered
	 */
	protected boolean checkStableRegions = CHECK_STABLE_REGIONS_EDEFAULT;

	/**
	 * The default value of the '{@link #getModalFormula() <em>Modal Formula</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModalFormula()
	 * @generated
	 * @ordered
	 */
	protected static final String MODAL_FORMULA_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getModalFormula() <em>Modal Formula</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModalFormula()
	 * @generated
	 * @ordered
	 */
	protected String modalFormula = MODAL_FORMULA_EDEFAULT;

	/**
	 * The default value of the '{@link #getStableRegions() <em>Stable Regions</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStableRegions()
	 * @generated
	 * @ordered
	 */
	protected static final int STABLE_REGIONS_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getStableRegions() <em>Stable Regions</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStableRegions()
	 * @generated
	 * @ordered
	 */
	protected int stableRegions = STABLE_REGIONS_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected NetworkImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ArnePackage.Literals.NETWORK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Node> getNodes() {
		if (nodes == null) {
			nodes = new EObjectContainmentWithInverseEList<Node>(Node.class, this, ArnePackage.NETWORK__NODES, ArnePackage.NODE__NETWORK);
		}
		return nodes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Edge> getEdges() {
		if (edges == null) {
			edges = new EObjectContainmentWithInverseEList<Edge>(Edge.class, this, ArnePackage.NETWORK__EDGES, ArnePackage.EDGE__NETWORK);
		}
		return edges;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NetworkActivation> getActivations() {
		if (activations == null) {
			activations = new EObjectContainmentEList<NetworkActivation>(NetworkActivation.class, this, ArnePackage.NETWORK__ACTIVATIONS);
		}
		return activations;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isCheckEquivalence() {
		return checkEquivalence;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCheckEquivalence(boolean newCheckEquivalence) {
		boolean oldCheckEquivalence = checkEquivalence;
		checkEquivalence = newCheckEquivalence;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ArnePackage.NETWORK__CHECK_EQUIVALENCE, oldCheckEquivalence, checkEquivalence));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isCheckModalFormula() {
		return checkModalFormula;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCheckModalFormula(boolean newCheckModalFormula) {
		boolean oldCheckModalFormula = checkModalFormula;
		checkModalFormula = newCheckModalFormula;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ArnePackage.NETWORK__CHECK_MODAL_FORMULA, oldCheckModalFormula, checkModalFormula));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isCheckStableRegions() {
		return checkStableRegions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCheckStableRegions(boolean newCheckStableRegions) {
		boolean oldCheckStableRegions = checkStableRegions;
		checkStableRegions = newCheckStableRegions;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ArnePackage.NETWORK__CHECK_STABLE_REGIONS, oldCheckStableRegions, checkStableRegions));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getModalFormula() {
		return modalFormula;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModalFormula(String newModalFormula) {
		String oldModalFormula = modalFormula;
		modalFormula = newModalFormula;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ArnePackage.NETWORK__MODAL_FORMULA, oldModalFormula, modalFormula));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getStableRegions() {
		return stableRegions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStableRegions(int newStableRegions) {
		int oldStableRegions = stableRegions;
		stableRegions = newStableRegions;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ArnePackage.NETWORK__STABLE_REGIONS, oldStableRegions, stableRegions));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public boolean hasUnknownStartLevels() {
		for (Node node : getNodes()) {
			if (node.getStartLevel()<0) return true;
		}
		return false;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public boolean hasDifferentialEdges() {
		for (Edge edge : getEdges()) {
			if (edge.getBaseLevels().isEmpty()) return true;
		}
		return false;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getNodes()).basicAdd(otherEnd, msgs);
			case ArnePackage.NETWORK__EDGES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getEdges()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				return ((InternalEList<?>)getNodes()).basicRemove(otherEnd, msgs);
			case ArnePackage.NETWORK__EDGES:
				return ((InternalEList<?>)getEdges()).basicRemove(otherEnd, msgs);
			case ArnePackage.NETWORK__ACTIVATIONS:
				return ((InternalEList<?>)getActivations()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				return getNodes();
			case ArnePackage.NETWORK__EDGES:
				return getEdges();
			case ArnePackage.NETWORK__ACTIVATIONS:
				return getActivations();
			case ArnePackage.NETWORK__CHECK_EQUIVALENCE:
				return isCheckEquivalence();
			case ArnePackage.NETWORK__CHECK_MODAL_FORMULA:
				return isCheckModalFormula();
			case ArnePackage.NETWORK__CHECK_STABLE_REGIONS:
				return isCheckStableRegions();
			case ArnePackage.NETWORK__MODAL_FORMULA:
				return getModalFormula();
			case ArnePackage.NETWORK__STABLE_REGIONS:
				return getStableRegions();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				getNodes().clear();
				getNodes().addAll((Collection<? extends Node>)newValue);
				return;
			case ArnePackage.NETWORK__EDGES:
				getEdges().clear();
				getEdges().addAll((Collection<? extends Edge>)newValue);
				return;
			case ArnePackage.NETWORK__ACTIVATIONS:
				getActivations().clear();
				getActivations().addAll((Collection<? extends NetworkActivation>)newValue);
				return;
			case ArnePackage.NETWORK__CHECK_EQUIVALENCE:
				setCheckEquivalence((Boolean)newValue);
				return;
			case ArnePackage.NETWORK__CHECK_MODAL_FORMULA:
				setCheckModalFormula((Boolean)newValue);
				return;
			case ArnePackage.NETWORK__CHECK_STABLE_REGIONS:
				setCheckStableRegions((Boolean)newValue);
				return;
			case ArnePackage.NETWORK__MODAL_FORMULA:
				setModalFormula((String)newValue);
				return;
			case ArnePackage.NETWORK__STABLE_REGIONS:
				setStableRegions((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				getNodes().clear();
				return;
			case ArnePackage.NETWORK__EDGES:
				getEdges().clear();
				return;
			case ArnePackage.NETWORK__ACTIVATIONS:
				getActivations().clear();
				return;
			case ArnePackage.NETWORK__CHECK_EQUIVALENCE:
				setCheckEquivalence(CHECK_EQUIVALENCE_EDEFAULT);
				return;
			case ArnePackage.NETWORK__CHECK_MODAL_FORMULA:
				setCheckModalFormula(CHECK_MODAL_FORMULA_EDEFAULT);
				return;
			case ArnePackage.NETWORK__CHECK_STABLE_REGIONS:
				setCheckStableRegions(CHECK_STABLE_REGIONS_EDEFAULT);
				return;
			case ArnePackage.NETWORK__MODAL_FORMULA:
				setModalFormula(MODAL_FORMULA_EDEFAULT);
				return;
			case ArnePackage.NETWORK__STABLE_REGIONS:
				setStableRegions(STABLE_REGIONS_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ArnePackage.NETWORK__NODES:
				return nodes != null && !nodes.isEmpty();
			case ArnePackage.NETWORK__EDGES:
				return edges != null && !edges.isEmpty();
			case ArnePackage.NETWORK__ACTIVATIONS:
				return activations != null && !activations.isEmpty();
			case ArnePackage.NETWORK__CHECK_EQUIVALENCE:
				return checkEquivalence != CHECK_EQUIVALENCE_EDEFAULT;
			case ArnePackage.NETWORK__CHECK_MODAL_FORMULA:
				return checkModalFormula != CHECK_MODAL_FORMULA_EDEFAULT;
			case ArnePackage.NETWORK__CHECK_STABLE_REGIONS:
				return checkStableRegions != CHECK_STABLE_REGIONS_EDEFAULT;
			case ArnePackage.NETWORK__MODAL_FORMULA:
				return MODAL_FORMULA_EDEFAULT == null ? modalFormula != null : !MODAL_FORMULA_EDEFAULT.equals(modalFormula);
			case ArnePackage.NETWORK__STABLE_REGIONS:
				return stableRegions != STABLE_REGIONS_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (checkEquivalence: ");
		result.append(checkEquivalence);
		result.append(", checkModalFormula: ");
		result.append(checkModalFormula);
		result.append(", checkStableRegions: ");
		result.append(checkStableRegions);
		result.append(", modalFormula: ");
		result.append(modalFormula);
		result.append(", stableRegions: ");
		result.append(stableRegions);
		result.append(')');
		return result.toString();
	}

} //NetworkImpl
